<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .box{
        z-index: 5;
        position: relative;
        float: left;
        margin-left: 18px;
        width: 372px;
        height: 254px;
        overflow: hidden;
    }
    .box a{
        z-index: 5;
        position: absolute;
        top: 118px;
        width: 18px;
        height: 32px;
        transition: all 0.3s;
    }
    .prev{
        left: 0;
        background: url(https://vr1.6rooms.com/tao/i/b1/7004789f991203600cc727938827a9d2.png) no-repeat;
    }
    .next{
        right: 0;
        background: url(https://vr1.6rooms.com/tao/i/v7/8d5be75ad94f301822de2da51cd901c0.png) no-repeat;
    }
    .box ul{
        width: 774px;
    transform: translateX(0px);
    margin: 0;
    padding: 0;
    }
    .box ul li{
        float: left;
    /* margin: 0 2px 5px; */
    /* width: 82px; */
    text-align: center;
    }
    ul li{
        list-style: none;
    }
    .red{
        background-color: red;
        width: 110px;
        height: 250px;
        /* margin-right: 20px; */
    }
    .blue{
        background-color: blue;
        width: 110px;
        height: 250px;
        /* margin-right: 20px; */
    }
    .yellow{
        background-color: yellow;
        width: 110px;
        height: 250px;
        /* margin-right: 20px; */
    }
    .dark{
        background-color: black;
        width: 110px;
        height: 250px;
        /* margin-right: 20px; */
    }
</style>
<body>
    <div class="box">
        <a class="prev">左</a>
        <a class="next">右</a>
        <ul>
            <li class="red"></li>
            <li class="red"></li>
            <li class="red"></li>
            <li class="blue"></li>
            <li class="blue"></li>
            <li class="blue"></li>
            <li class="yellow"></li>
            <li class="yellow"></li>
            <li class="yellow"></li>
            <li class="dark"></li>
            <li class="dark"></li>
            <li class="dark"></li>
        </ul>
    </div>
</body>
<script src="./jquery-1.11.3.min.js"></script>
<script>
    //简易版照片墙
var FerrisWallAni = function(){
    this.initialize.apply(this, arguments);
}
$.extend(FerrisWallAni.prototype, {
    initialize: function(options){
        this.elem = $(options.elem);
        this.showNum = options.showNum || 3;
        this.loop = options.loop || false;
        this.listBox = this.elem.find('ul');
        this.btnPrev = this.elem.find('a.prev');
        this.btnNext = this.elem.find('a.next');

        this.reset();
        this.events();
    },
    events: function(){
        var that = this;

        this.btnNext.on('click', function(event){
            that.next();
        });
        this.btnPrev.on('click', function(event){
            that.prev();
        });

    },
    reset: function(){
        this.cur = 0;
        this.items = this.listBox.find('li');
        this.itemWidth = this.items.outerWidth(true);
        this.len = this.items.length;

        this.listBox.css('width', this.itemWidth*this.items.length);
        this.listBox.css('transform', 'translateX(0)');
        this.setBtns();
    },
    setBtns: function(){
        if(this.cur == 0){
            this.btnPrev.addClass('disabled');
        }else{
            this.btnPrev.removeClass('disabled');
        }

        if(this.len-this.cur <= this.showNum){
            this.btnNext.addClass('disabled');
        }else{
            this.btnNext.removeClass('disabled');
        }
    },
    next: function(){
        console.log('2222')
        var num = this.showNum;
        var left = 0;
        var maxLeft = this.itemWidth*this.len - this.elem.width() - parseInt(this.items.css('marginRight'))*2;

        if(this.len-this.cur < num*2){
            num = this.len - this.cur - num;
        }
        this.cur = this.cur + num;

        left = Math.min(this.itemWidth*this.cur, maxLeft);

        this.listBox.css('transform', 'translateX('+(-1*left)+'px)');
        this.setBtns();
    },
    prev: function(){
        console.log('1111')
        var num = this.showNum;
        if(this.cur < num){
            num = this.cur;
        }
        this.cur = this.cur - num;

        this.listBox.css('transform', 'translateX('+(-1*this.itemWidth*this.cur)+'px)');
        this.setBtns();
    }
});


new FerrisWallAni({
                elem: '.box',
                showNum: 3,
            });
</script>
</html>